﻿@model Accounting.ViewModel.BillViewModel
@{
    ViewBag.Title = "Edit";
}
<h2>
    Edit</h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Bill</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.CategoryId, "Category")
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.CategoryId, Model.Categories, "[Select Category]")
            @Html.ValidationMessageFor(model => model.CategoryId)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.SubCategoryId, "SubCategory")
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.SubCategoryId, Enumerable.Empty<SelectListItem>(), "[Select Sub Category]")
            @Html.ValidationMessageFor(model => model.SubCategoryId)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Date)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Date)
            @Html.ValidationMessageFor(model => model.Date)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Remark)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Remark)
            @Html.ValidationMessageFor(model => model.Remark)
        </div>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript">
    $('#CategoryId').change(function () {
        var categoryId = $(this).val();
        if (categoryId != null) {
            $.getJSON('@Url.Action("SubCategories")', { categoryId: categoryId }, function (subCategories) {
                var subCategoryDropDown = $('#SubCategoryId');
                subCategoryDropDown.empty();
                $.each(subCategories, function (index, subCategory) {
                    subCategoryDropDown.append($('<option/>', {
                        value: subCategory.Id,
                        text: subCategory.Name
                    }));
                });
            });
        }
    });
</script>
